package com.pnnd;

import com.pnnd.utils.NeedInit;

import java.util.ArrayList;
import java.util.List;

public class StringDTypeObject extends DTypeObject {

    private List<DTypeObject> subTypes = new ArrayList<>();

    protected StringDTypeObject() {
        super("string", "dtype.string", 7);
    }

    @Override
    public Class<?> getJvmKlass() {
        return String.class;
    }

    @Override
    public NeedInit create() {
        return new StringDTypeObject();
    }

    /**
     * 创建固定长度的字符串子类型
     * @param length 子类型的字符串长度
     * @return 创建的子类型
     */
    public DTypeObject createSubType(int length){
        DTypeObject typeObject = new StringDTypeObject();
        typeObject.init();

        this.elementLength = length;
        this.fixLength = true;
        this.baseType = false;
        this.name += length;
        this.subTypes.add(typeObject);

        return typeObject;
    }
}
